<?php

namespace App\Controller;

use App\Game\Core\Djs;
use Hyperf\Di\Annotation\Inject;
use Hyperf\Contract\ConfigInterface;

class ShareController extends AbstractController
{

    // 分享复活
    public function rebirth()
    {
        $account = $this->request->post('account');
        $playerInfo = Djs::getDjsPlayerData($account);
        if (empty($playerInfo)) {
            return $this->output(1, 'OK', ['status' => '暂未开局大奖赛', 'success' => 0]);
        }
        if ($playerInfo['status'] == 1) {
            return $this->output(1, 'OK', ['status' => '已经复活不要重复点击', 'success' => 0]);
        }
        if ($playerInfo['alive'] >= 3) {
            return $this->output(1, 'OK', ['status' => '当日复活最多3次', 'success' => 0]);
        }
        $left_time = $playerInfo['end_time'] - time();
        if ($left_time <= 0) {
            return $this->output(1, 'OK', ['status' => '当前大奖赛已结束，不能复活', 'success' => 0]);
        }
        $stage = $playerInfo['stage'] - 1 - 1;
        $playerInfo['status'] = 1;
        $playerInfo['stage'] = $stage <= 0 ? 0 : $stage;
        $playerInfo['alive'] += 1;

        Djs::updatePlayerData($account, $playerInfo);
        return $this->output(1, 'OK', ['status' => 'success', 'times' => $playerInfo['alive'], 'success' => 1]);
    }
}